<?php
    session_start();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link href="css/index.css" rel="stylesheet" type="text/css">
</head>
<body>
<iframe frameborder="0" marginwidth="0" marginheight="0" width="100%" height="60px" scrolling="no" src="header.php"></iframe>
<div class="body">
    <div id="row">
        <form id="form" method="post"
              enctype="multipart/form-data">
            <input name="name" type="text" placeholder="cuisineName" />
            <input name="desc" type="text" placeholder="description" />
            <input name="file" type="file"/>
            <button type="button" onclick="save()">save</button>
        </form>
    </div>
</div>
<script src="js/jquery.js" type="application/javascript"></script>
<script type="application/javascript">
    function save() {
        var formData = new FormData($("#form")[0]);
        $.ajax({
            url: "http://localhost:8080/cuisine/server/controller/add.php",
            type: "post",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success(data){
                console.log(data);
                if (!data) {
                    alert("save failed");
                    return;
                }
                alert("save success");
                // return;
                window.location.href="index.php";
            },
            error(e) {
                console.log(e);
            }
        })
    }
</script>
</body>
</html>